package com.ocom.payconfig.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.payconfig.EntityXfMealLeave;
import com.ocom.common.request.payconfig.GetOrderMealLeaveRequest;
import com.ocom.common.request.payconfig.MealLeaveReports;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.XfMealLeaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;


@Slf4j
@RestController
public class XfMealLeaveController {


    @Autowired
    private XfMealLeaveService xfMealLeaveService;

    @PostMapping(PayConfigUrl.URL_consumeReports_MealLeaveReports)
    public Result queryMealLeave(@RequestBody MealLeaveReports mealLeaveReports) {
        List<EntityXfMealLeave> xfMealLeaveVos = xfMealLeaveService.queryMealLeave(mealLeaveReports.getCompanyId().longValue(),mealLeaveReports);

        return ResultUtil.success(xfMealLeaveVos);
    }


    @PostMapping(PayConfigUrl.URL_getOrderMealLeave)
    public Result getOrderMealLeave(@RequestBody GetOrderMealLeaveRequest getOrderMealLeaveRequest) {
        List<EntityXfMealLeave> xfMealLeaveVos = xfMealLeaveService.getOrderMealLeave(getOrderMealLeaveRequest.getComId(),
                getOrderMealLeaveRequest);
        return ResultUtil.success(new PageInfo<>(xfMealLeaveVos));
    }

    @PostMapping(PayConfigUrl.URL_setOrderMealLeave)
    public Result setOrderMealLeave(@RequestBody EntityXfMealLeave xfMealLeave) throws ParseException {
        log.info("插入请假 【{}】",xfMealLeave);
        int result = xfMealLeaveService.setOrderMealLeaveRequest(xfMealLeave.getComId().longValue(),xfMealLeave);
        return ResultUtil.success(result);
    }
}
